<template>
  <div class="login-container">

    <div style="height:100%;position: relative;">
      <img src="~assets/img_login_right.png" style="position: absolute;right: 0;height: 100%;" />
      <img src="~assets/img_login_left.png" style="position: absolute;width: 18%;left: 0;" />

      <div
        style="width: 25%;position: absolute;top: 50%;transform: translateY(-50%);left: 15%;box-shadow: 0px 0px 20px 10px #d3d3d3;">
        <div class="login_module" style="display: flex;align-items: center;flex-direction: column;border-radius: 10px;;
   padding:50px 20px">
          <div
            style="font-size: 30px;text-align: center;color: white; font-family: 微软雅黑;margin-bottom: 20px;font-weight: bold;color: black;">
            隐患排查小邦手
          </div>
          <div style="">
            <el-input v-model="form.userId" placeholder="用户名" prefix-icon="el-icon-user"
              style="width: 300px;" @keyup.enter.native="clickLogin">

            </el-input>
          </div>
          <div style="margin-top: 20px;">
            <el-input v-model="form.password" type="password" placeholder="Password"
              prefix-icon="el-icon-lock" style="width: 300px;" @keyup.enter.native="clickLogin">
            </el-input>
          </div>
          <div style="font-size: 13px;color: red;font-family: 微软雅黑;margin-top: 10px;">
            {{ loginTips }}
          </div>
          <el-button @click="clickLogin" :loading="logining" style="width:205px;margin-top: 40px;"
            color="#ff6034" block square type="primary">登录</el-button>
        </div>
      </div>
      <!-- <img src="@/assets/logo.png" style="width:150px;" /> -->

    </div>

    <div style="position: absolute;bottom: 10px;left: 390px;">
      <Foot />
    </div>
  </div>
</template>
<script>
import { doLogin } from '@/service/user/index';
import Foot from '@/layout/foot';
export default {
  name: 'Login',
  components: { Foot },
  data() {
    return {
      form: {
        userId: '',
        password: '',
      },
      logining: false,
      redirect: undefined,
      loginTips: '',
    };
  },

  watch: {
    $route: {
      handler(route) {
        this.redirect = (route.query && route.query.redirect) || '/';
      },
      immediate: true,
    },
  },
  mounted() {
    this.form.userId = '';
    this.form.password = '';

    // this.clickLogin()
  },
  methods: {
    handleRoute() {
      return this.redirect === '/404' || this.redirect === '/403'
        ? '/'
        : this.redirect;
    },
    async clickLogin() {
      this.loginTips = '';
      this.logining = true;
      try {
        let res = await doLogin(this.form);
        if (res.success) {
          sessionStorage.setItem('user', JSON.stringify(res.data));
          sessionStorage.setItem('Authorization', res.data.accessToken);
          console.log('router');
          this.$router.push({ path: '/config/risk-table' });
        } else {
          this.loginTips = res.rtn_message;
        }
      } catch (error) {
        console.log('error', error);
      }
      this.logining = false;
    },
  },
};
</script>
<style >
.login-container {
  width: 100%;
  height: 100vh;
  /* background: url('~@/assets/login_images/login_background.png'); */
  background-size: cover;
}
.login_module {
  background-color: white;
  border-radius: 10px;
}
</style>
